package com.project.oauth2;

import com.alibaba.fastjson2.JSON;
import com.project.dao.OAuth2ClientDetailsDao;
import com.project.entity.OAuth2ClientDetailsEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.ClientRegistrationException;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class ClientDeatisService implements ClientDetailsService {

    private static final Logger log = LoggerFactory.getLogger(com.project.oauth2.ClientDeatisService.class);
    @Resource
    private OAuth2ClientDetailsDao clientDetailsDao;


    @Override
    public ClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException {
        OAuth2ClientDetailsEntity entity = new OAuth2ClientDetailsEntity();
        entity.setClientID(clientId);
        OAuth2ClientDetailsEntity find = clientDetailsDao.findOne(entity);
        com.project.oauth2.ClientDetails clientDetails = new com.project.oauth2.ClientDetails(find);
        return clientDetails;
    }
}
